home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Virtual User tools / SPEC S&L v.1.0.1 / Libraries / Utility.Lib < prev    next >
Encoding:
Text File  |  1993-12-17  |  7.2 KB  |  216 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        Utility.Lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
  9. #
  10. #    Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #     <1.0.5>    11/19/93    KTA        Changed teh variables that BeginTimer() and EndTimer() use
  19. #                                    because they were being overwritten by performance testing.
  20. #     <1.0.4>     9/10/93    KTA        Removed all slang phrases from output.
  21. #     <1.0.3>      8/9/93    KTA        Added GetCurrentTime().
  22. #     <1.0.2>      7/6/93    KTA        Performance support- changed Timer() parameters.
  23. #        <1+>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  24. #
  25. # ****************************************************************************
  26. #
  27.  
  28. #########################################################################
  29. #                             Timer(timeParam)
  30. #=======================================================================
  31. # Author:              DM
  32. # Description:        Calculates the time between two time descriptors 
  33. # Parameters:        timeParam - Specifier - what to return
  34. #                    1 - return (theTime) - full descriptor
  35. #                    2 - return ({"{theHour}:{theSec}",theHour,theSec});
  36. #                    3 - return (("{theMonth}/{theDay}/{theYear}"))
  37. #                    4 - CurrentTime - formatted
  38. # Example:            Timer(1);
  39. #=======================================================================
  40. # History:
  41. #
  42. #########################################################################
  43. TASK Timer(timeParam:=1) 
  44. begin
  45.     if (timeParam = 1) 
  46.         returnVal := match [time];
  47.     else
  48.     begin
  49.         theTime := match [time h:?theHour s:?theSec d:?theDay m:?theMonth y:?theYear];
  50.         if (timeParam = 2)
  51.             returnVal :=   {"{theHour}:{theSec}",theHour,theSec};
  52.         else if (timeParam = 3) 
  53.             returnVal :=   "{theMonth}/{theDay}/{theYear}";
  54.         else if (timeParam = 4) 
  55.         begin 
  56.             HourString := numToStr (theHour);
  57.             if(Card(HourString) = 3)
  58.                 HourString := HourString[1] + ':' + HourString[2] + HourString[3];
  59.             else
  60.                 HourString := HourString[1] + HourString[2] + ':' + HourString[3] + HourString[4];
  61.             SecString := numToStr (theSec);
  62.             if( Card(SecString) = 1) 
  63.                 SecString := '0' + SecString;
  64.             CurrentTime := HourString + ':' + SecString;
  65.             Println "The current time is - ",CurrentTime;
  66.                 returnVal :=   CurrentTime;
  67.         end;
  68.     end;
  69.     return(returnVal);
  70. end; # Timer()
  71.  
  72.  
  73. #########################################################################
  74. #                 ETime(time1, time2, mode)
  75. #=======================================================================
  76. # Author:              DM
  77. # Description:        Calculates the time between two time descriptors 
  78. # Parameters:        time1, time2 - times to compare
  79. # Returns:            mode := 0 Difference between the two in secs
  80. # Returns:            mode := 1 Difference between the two "{eh}:{em}:{es}"
  81. # Example:            ETime(time1, time2);
  82. #=======================================================================
  83. # History:
  84. #########################################################################
  85. task ETime(time1, time2, mode := 1) 
  86. begin
  87.     h1:= 0; h2 := 0; m1:= 0; m2 := 0; 
  88.     t1 := time1.h; t2 := time2.h; s1 := time1.s; s2 := time2.s;
  89.     if(t1 > t2) begin
  90.         t1 := time2.h; t2 := time1.h; s1 := time2.s; s2 := time1.s;
  91.     end;
  92.     h1 := t1/100; m1 := t1 mod 100;        # tx is in military time e.g. 1330 for 1:30 PM
  93.     h2 := t2/100; m2 := t2 mod 100;
  94.  
  95.     eh := h2-h1; em := m2-m1;                # eh = elapsed hours, em = elapsed mins
  96.     
  97.     if(em<0) begin                            # if minutes are negative carry an hour
  98.         em := em + 60; eh := eh -1;
  99.     end;
  100.         
  101.     # get the diff for seconds and manipulate minutes if required
  102.     es := s2 - s1;
  103.     if(es<0) begin                            # if seconds are negative carry a minute
  104.         if (em>0) begin
  105.             es := es + 60; em := em -1;
  106.         end;
  107.         else if (eh>0) begin
  108.             es := es + 60; eh := eh - 1; em := 59;
  109.         end;
  110.         else begin
  111.             es := -es;
  112.         end;
  113.     end;
  114.     
  115.     if (mode = 0) 
  116.         theETime := eh * 3600 + em * 60 + es;
  117.     else if (mode = 1) 
  118.         theETime := "{eh}:{em}:{es}";
  119.     
  120.     return theETime;
  121.     
  122. end; # ETime()
  123.  
  124.  
  125. #########################################################################
  126. #             BeginTimer()
  127. #=======================================================================
  128. # Author:              ML
  129. # Description:        Starts the timer
  130. # Parameters:        none
  131. # Returns:            None
  132. #=======================================================================
  133. # History:
  134. #
  135. ########################################################################
  136. TASK BeginTimer() 
  137. begin
  138.     global gTheStartTime := Timer();
  139.     println;
  140.     Println "Starting the timer";
  141. end;
  142.  
  143. #########################################################################
  144. #             EndTimer()
  145. #=======================================================================
  146. # Author:              ML
  147. # Description:        Ends the timer
  148. # Parameters:        none
  149. # Returns:            None
  150. #=======================================================================
  151. # History:
  152. # KTA    9/9/93    Remove the slang 'Yah Sure' from the output.
  153. ########################################################################
  154. TASK EndTimer() 
  155. begin
  156.     global gTheStartTime;
  157.     endTime := Timer();
  158.     if (isUndefined(gTheStartTime))
  159.         elTime := "the elapsed time routine didn't work!!!";
  160.     else
  161.         elTime := ETime(gTheStartTime,endTime);
  162.     println "Total Elapsed time was ", elTime;
  163. end;
  164.  
  165.  
  166. #########################################################################
  167. #             GetCurrentTime(NeedMeridian, returnDate)
  168. #=======================================================================
  169. # Author:              Derived from VU Example Libraries
  170. # Description:        This task returns the current time.  The format is as follows:
  171. #                    <hour of day>:<minutes>:<seconds> <AM or PM>
  172. #                    It also takes one parameter that indicates whether the 
  173. #                    date should be printed. If the actual parameter passed 
  174. #                    is a true value, the current date is also printed.
  175. #                    If no parameter is passed, the date is printed by default.
  176. #                    The format of the date is as follows:
  177. #                        <month>/<day>/<year>
  178. # Parameters:        NeedMeridian - Adds AM/PM if true
  179. #                    returnDate -  Adds date if true
  180. # Returns:            Current Time (& Date) string
  181. #=======================================================================
  182. # History:
  183. #
  184. ########################################################################
  185. TASK GetCurrentTime(NeedMeridian := true, returnDate := true)
  186. begin
  187.     timeString := "";
  188.     meridian := '';
  189.     match [time h:?hour s:?secs d:?day m:?month y:?year];
  190.     hourOfDay := (hour / 100);
  191.     if (hour < 1200) 
  192.     begin # in AM
  193.         if (hourOfDay) 
  194.             timeString := numToStr(hourOfDay);
  195.         else 
  196.             timeString := '12';
  197.         if (needMeridian)
  198.             meridian := ' AM';
  199.     end;
  200.     else 
  201.     begin # in PM
  202.         if (hourOfDay = 12)
  203.             timeString := timeString + numToStr(hourOfDay);
  204.         else
  205.             timeString := timeString + numToStr(hourOfDay - 12);
  206.         if (needMeridian)
  207.             meridian := ' PM';
  208.     end;
  209.     timeString := timeString + ':' + numToStr((hour mod 100) / 10) + 
  210.                     numToStr(hour mod 10) + ':' + numToStr(secs) + meridian;
  211.     if (returnDate) 
  212.         timeString := timeString + " " + numToStr(month) + "/" + numToStr(day) + "/" + 
  213.                         numToStr((year mod 100) / 10) + numToStr(year mod 10);
  214.     return timeString;
  215. end;
  216.